Skip to content

Fix 500 error when viewing questions with solutions from deleted users #6561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

smithellis
Copy link
Contributor

When a user who marked an answer as a solution is later deleted, viewing the question was causing a 500 error. This occurred because the Question.solver property tried to retrieve the user from the solver_id metadata but failed since the user no longer exists in the database.

The fix adds error handling in the Question.solver property to gracefully return None when User.DoesNotExist is raised, which is properly handled by the template's existing conditional checks.

Steps to reproduce the fixed issue:

  1. User A submits a question
  2. User B leaves a reply
  3. User A marks User B's reply as solution
  4. Delete User A
  5. Navigate back to the question (previously 500 error, now works properly)

When a user who marked an answer as a solution is later deleted, viewing
the question was causing a 500 error. This occurred because the Question.solver
property tried to retrieve the user from the solver_id metadata but failed
since the user no longer exists in the database.

The fix adds error handling in the Question.solver property to gracefully
return None when User.DoesNotExist is raised, which is properly handled by
the template's existing conditional checks.

Steps to reproduce the fixed issue:
1. User A submits a question
2. User B leaves a reply
3. User A marks User B's reply as solution
4. Delete User A
5. Navigate back to the question (previously 500 error, now works properly)
@smithellis smithellis requested a review from Copilot March 13, 2025 19:31
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a 500 error that occurs when viewing questions solved by a deleted user by adding error handling in the Question.solver property.

  • Adds a try/except block to catch User.DoesNotExist when retrieving the solver.
  • Ensures that a missing user returns None to be properly handled by the template.

@akatsoulas akatsoulas merged commit e5d888d into mozilla:main Mar 14, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants